import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class ClipboardFavorites implements Serializable
{
	private static final long serialVersionUID = -3671352841447328702L;

	private static ClipboardFavorites instance = null;
	
	List<TransparentMenuItem> list = new ArrayList<TransparentMenuItem>();
	
	private ClipboardFavorites() {}
	
	public static ClipboardFavorites getInstance()
	{
		if (instance == null) {
			instance = new ClipboardFavorites();
		}
		return instance;
	}

	public static void save(String path)
	{
		try {
			FileOutputStream fileOut = new FileOutputStream(path);
			ObjectOutputStream objOut = new ObjectOutputStream(fileOut);
			objOut.writeObject(instance);
			objOut.close();
			fileOut.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void load(String path)
	{
		try {
			FileInputStream fileIn = new FileInputStream(path);
			ObjectInputStream objIn = new ObjectInputStream(fileIn);
			instance = (ClipboardFavorites) objIn.readObject();
			objIn.close();
			fileIn.close();
		} catch (IOException | ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	public List<TransparentMenuItem> getList()
	{
		// TODO Auto-generated method stub
		return list;
	}

	public void add(String string)
	{
		list.add(new TransparentMenuItem(string));
	}
	
	public String remove (String string) {
		int index = -1;
		index = list.lastIndexOf(new TransparentMenuItem(string));
		return list.remove(index).getText();
		//TODO 
	}
}
